"""
@name : 2020-05-29作业
@author : maxueyan
@projectname: sanchuang
"""

#猜数字
import random
secretNum = random.randint(1,20)
print("这是一个位于 1-20 之间的数")
for i in range(3):
    i += 1
    print("请输入猜测的数：")
    guess = int(input())
    if guess == 0:
        break
    if guess < secretNum:
        print("猜小了")
    elif guess > secretNum:
        print("猜大了")
    else:
        break
if(guess == secretNum):
    print("猜对了，就是",str(guess))
else:
    print("很遗憾，正确的答案应该是",str(secretNum))
print(f"你一共猜了{i}次")

# 计算复利
amount = int(input("请输入您要存入的金额："))
target_amount = int(input("请输入您的目标金额："))
i = 0
while amount <= target_amount:
    i += 1
    interest = amount * 0.05 * 1
    total_amount = amount + interest
    print(f"第{i}年本金{amount}+利息{interest}：")
    amount = total_amount
    if amount >= target_amount:
        break
print(f"需要{i}年")

#空气质量查询工具
num = input("请输入PM2.5的值：")
while num != "q":
    num = int(num)
    if 0<num<50:
        print("空气质量状况为优！")
    elif 51<num<100:
        print("空气质量状况为良！")
    elif 101<num<150:
        print("空气质量状况为轻度污染！")
    elif 151<num<200:
        print("空气质量状况为中度污染！")
    elif 201<num<300:
        print("空气质量状况为重度污染！")
    else:
        print("空气质量状况为严重污染！")
    num = input("请输入PM2.5的值：")
    continue

#猜大小游戏
import random
str1 = input("请输入你的猜测：")
gold_bean = 1000
win = 0
fre = 0
wins_rate = 0
while str1 != "exit":
    num1 = random.randint(1, 6)
    num2 = random.randint(1, 6)
    num3 = random.randint(1, 6)
    sum = num1+num2+num3
    if sum<=10:
        str2 = "小"
    else:
        str2 = "大"
    if str1 == str2:
        print("猜对了！")
        win += 1
        gold_bean += 100
    else:
        print("猜错了！")
        gold_bean -= 100
    fre += 1
    if gold_bean <= 100:
        print("很抱歉！你的金豆不足")
        break
    str1 = input("请输入你的猜测：")
wins_rate = win / fre
print(f"你一共玩了{fre}次,胜率为{wins_rate}")







